<template>
  <div class="example">
    <div :class="{'showSecond':($store.state.buyTicket.surplusData&&$store.state.buyTicket.surplusData<60)}" id="flipdown" class="flipdownClass"></div>
  </div>
</template>
<script>
import { FlipDown } from "./../../../../utils/flipdown.js";
export default {
  data() {
    return {};
  },
  mounted() {
    const flip = new FlipDown(
      new Date().getTime() / 1000 + this.$store.state.buyTicket.surplusData
    );
    flip.start().ifEnded(() => {
      // 倒计时结束后⾃自动刷新⻚页⾯面
      this.$store.state.buyTicket.noSale = true;
      this.$store.state.buyTicket.ifShowTimeDown = false;
      location.reload(); //刷新页面
    });
  },
  // mounted() {
  //   this.stareTimeDown();
  // },
  methods: {
    // stareTimeDown() {
    //   let nowDate = this.$store.state.buyTicket.createDate;
    //   let endDate = this.$store.state.buyTicket.startSaleDate;
    //   // 1566161611000 "nowDate" "2019.08.19 04:53:31"
    //   // 1568161611000 "endDate" "2019.09.11 08:26:51"
    //   console.log(
    //     nowDate,
    //     "nowDate",
    //     this.$moment(nowDate).format("YYYY.MM.DD HH:mm:ss")
    //   );
    //   console.log(
    //     endDate,
    //     "endDate",
    //     this.$moment(endDate).format("YYYY.MM.DD HH:mm:ss")
    //   );
    //   let res = ((Number(endDate) || 0) - (Number(nowDate) || 0)) / 1000; //多少秒
    //   // console.log("res", res);
    //   let twoDaysFromNow = new Date().getTime() / 1000 + 1 * res + 1;
    //   let flipdown = new FlipDown(twoDaysFromNow)
    //     .start()
    //     .ifEnded(() => {
    //       console.log("The countdown has ended!");
    //       // 倒计时结束后⾃自动刷新⻚页⾯面
    //       // this.$store.state.buyTicket.noSale = true;
    //       // this.$store.state.buyTicket.ifShowTimeDown = false;
    //       location.reload(); //刷新页面
    //     });
    //   let body = document.body;
    //   body.classList.toggle("light-theme");
    // }
  }
};
</script>


<style  lang="scss">
/* Rotor tops */
.flipdownClass .rotor,
.flipdownClass .rotor-top,
.flipdownClass .rotor-leaf-front {
  color: #ffffff;
  background-color: #151515;
}
/* Rotor bottoms */
.flipdownClass .rotor-bottom,
.flipdownClass .rotor-leaf-rear {
  color: #efefef;
  background-color: #202020;
}

.flipdownClass {
  overflow: visible;
  width: 510px;
  height: 80px;
  height: auto;
  // font-family: sans-serif;
  font-weight: bold;
  display: flex;
  flex-direction: row;
  justify-content: left;
  align-items: baseline;

  .rotor-group {
    position: relative;
    float: left;
    padding-right: 40px;

    /* 暴力隐藏。。。 */
    &:nth-last-child(1) {
      display: none;
    }
  }

  .rotor-group-heading:before {
    display: block;
    height: 28px;
    line-height: 28px;
    text-align: center;
  }

  .rotor {
    position: relative;
    float: left;
    width: 40px;
    height: 56px;
    margin: 0px 5px 0px 0px;
    border-radius: 4px;
    font-size: 40px;
    text-align: center;
    perspective: 200px;

    &:last-child {
      margin-right: 0;
    }

    &:after {
      content: "";
      z-index: 2;
      position: absolute;
      bottom: 0px;
      left: 0px;
      width: 40px;
      height: 28px;
      border-radius: 0px 0px 4px 4px;
      border-top: solid 1px #151515;
    }
  }

  .rotor-top,
  .rotor-bottom {
    overflow: hidden;
    position: absolute;
    width: 40px;
    height: 28px;
  }

  .rotor-leaf {
    z-index: 1;
    position: absolute;
    width: 40px;
    height: 56px;
    transform-style: preserve-3d;
    transition: transform 0s;
  }

  .rotor-leaf.flipped {
    transform: rotateX(-180deg);
    transition: all 0.5s ease-in-out;
  }

  .rotor-leaf-front,
  .rotor-leaf-rear {
    overflow: hidden;
    position: absolute;
    width: 40px;
    height: 28px;
    margin: 0;
    transform: rotateX(0deg);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }

  .rotor-leaf-front {
    line-height: 56px;
    border-radius: 4px 4px 0px 0px;
  }
  .rotor-leaf-rear {
    line-height: 0px;
    border-radius: 0px 0px 4px 4px;
    transform: rotateX(-180deg);
  }
  .rotor-top {
    line-height: 80px;
    border-radius: 4px 4px 0px 0px;
  }
  .rotor-bottom {
    bottom: 0;
    line-height: 0px;
    border-radius: 0px 0px 4px 4px;
  }

  .rotor-group:nth-child(1) .rotor-group-heading:before {
    content: "天";
    position: absolute;
    bottom: 0px;
    right: 16px;
    // font-family: PingFangSC-Regular;
    font-size: 18px;
    color: #9b9ea0;
  }
  .rotor-group:nth-child(2) .rotor-group-heading:before {
    content: "时";
    position: absolute;
    bottom: 0px;
    right: 16px;
    // font-family: PingFangSC-Regular;
    font-size: 18px;
    color: #9b9ea0;
  }
  .rotor-group:nth-child(3) .rotor-group-heading:before {
    content: "分";
    position: absolute;
    bottom: 0px;
    right: 16px;
    // font-family: PingFangSC-Regular;
    font-size: 18px;
    color: #9b9ea0;
  }

  .rotor-group:nth-child(4) .rotor-group-heading:before {
    content: "秒";
    position: absolute;
    bottom: 0px;
    right: 16px;
    // font-family: PingFangSC-Regular;
    font-size: 18px;
    color: #9b9ea0;
  }
}

.showSecond {
  .rotor-group {
    /* 暴力隐藏。。。 */
    &:nth-last-child(1) {
      display: block;
    }
    &:nth-last-child(4) {
      display: none;
    }
  }
}
</style>

<style  scoped>
.example {
  width: auto;
  height: auto;
}
#flipdown {
  width: auto;
  height: auto;
}
</style>
